import { _decorator, Component, Node } from 'cc';
import { ProtoMgr } from '../framework/Net/ProtoMgr';
import Stype from './Stype';
import Cmd from './Cmd';
import NetEventMgr from './NetEventMgr';
const { ccclass, property } = _decorator;

@ccclass('GameApp')
export class GameApp extends Component {
    public static Instance: GameApp = null;

    protected onLoad(): void {
        if (GameApp.Instance === null) {
            GameApp.Instance = this;
        }
        else {
            this.destroy();
            return;
        }
    }

    public gameStart(): void {
        // TODO: 开始游戏逻辑

        this.scheduleOnce(()=>{
            this.EnterGameScene();
        }, 3)
        
    }

    public EnterGameScene(): void {
        // 测试
        var msg = {uname: "test", upwd: "202CB962AC59075B964B07152D234B70"};
        var stype = Stype.Auth;
        var ctype = Cmd.UnameLoginReq; // 
        NetEventMgr.Instance.sendMsg(stype, ctype, msg);
        // end


        // // 测试
        // let msg = {uname: "test", upwd: "123456"}
        // let buf = ProtoMgr.Instance.SerializeMsg("UnameLoginReq", msg);
        // console.log(buf);

        // let msg2 = ProtoMgr.Instance.DeserializeMsg("UnameLoginReq", buf);
        // console.log(msg2);
    }

}


